/* Papastefanos Serafeim */
/* Sunarthseis gia dhmiouria soap mhnumatwn */

#include <stdio.h>
#include <upnp/ixml.h>
#include "client.h"
#include "helpers.h"

/****************
 Oi akolou9es sunarthseis dhmiourgoun ta soap envelopes gia ka9e RPC 
 ***************/

// Dhmiourgei to soap message gia ena mhnuma Inform. Oi parametroi einai oi
// antistoixes domes se C me tis parametrous tou TR69, ka9ws kai ena header.
IXML_Document *createInform(SoapHeader *sh, DeviceIdStruct deviceId, EventList *events, unsigned int maxEnvelopse, DateTime currentTime, unsigned int retryCount, ParameterValueList *parameterList);

// Dhmiourgei to soap message gia ena mhnuma InformResponse. Oi parametroi einai to
// header ka9ws kai ta maximum envelopes tou server.
IXML_Document *createInformResponse(SoapHeader *sh, unsigned int maxEnvelopes);

// Dhmiourgei to SetParameterValues mhnuma
IXML_Document *createSetParameterValues(SoapHeader *sh, ParameterValueList *parameterList, char *parameterKey);
// Dhmiourgei to SetParameterValuesResponse mhnuma
IXML_Document *createSetParameterValuesResponse(SoapHeader *sh, int status);

// Dhmiourgei to GetParameterValues mhnuma
IXML_Document *createGetParameterValues(SoapHeader *sh, StringList *parameterNames);
// Dhmiourgei to GetParameterValuesResponse mhnuma
IXML_Document *createGetParameterValuesResponse(SoapHeader *sh, ParameterValueList *parameterList);

// Dhmiourgei to GetParameterNames mhnuma
IXML_Document *createGetParameterNames(SoapHeader *sh, char *parameterPath, unsigned short int nextLevel);
// Dhmiourgei to GetParameterNamesResponse mhnuma
IXML_Document *createGetParameterNamesResponse(SoapHeader *sh, char *path, unsigned short int nextLevel);

// Dhmiourgei to GetRPCMethods mhnuma
IXML_Document *createGetRPCMethods(SoapHeader *sh);
// Dhmiourgei to GetRPCMethodsResponse mhnuma
IXML_Document *createGetRPCMethodsResponse(SoapHeader *sh);

// Dhmiourgei to Reboot mhnuma
IXML_Document *createReboot(SoapHeader *sh, char *cmdKey);
// Dhmiourgei to RebootResponse mhnuma
IXML_Document *createRebootResponse(SoapHeader *sh);

// Dhmiourgei to Download mhnuma
IXML_Document *createDownload(SoapHeader *sh, char *cmdKey, char *ftype, char *URL, char *uname, char *pwd, unsigned int fsize, char *tgetfname, unsigned int dsecs, char *surl, char *furl);
// Dhmiourgei to DowloadResponse mhnuma
IXML_Document *createDownloadResponse(SoapHeader *sh, short int status, DateTime* startTime, DateTime* completeTime);

// Dhmiourgei to Upload mhnuma
IXML_Document *createUpload(SoapHeader *sh, char *cmdKey, char *ftype, char *URL, char *uname, char *pwd, unsigned int dsecs);
// Dhmiourgei to UploadResponse mhnuma
IXML_Document *createUploadResponse(SoapHeader *sh, short int status, DateTime* startTime, DateTime* completeTime);


// Dhmiourgei ena Fault response
IXML_Document *createFaultResponse(SoapHeader *sh, int code);


// Dhmiourgei ena Fault response gia thn SetParameterNames
IXML_Document *createSetFaultResponse(SoapHeader *sh, ParameterValueList *params, int * errors);

/*******************
 Oi akolou9es sunarthseis einai voh9htikes kai xrhsimopoiountai apo tis
 parapanw sunarthseis. De 9a prepei na klh9oun anejarthta. 
 ***************/
// Metafrazei mia domh DeviceStruct se soap
IXML_Element *createDeviceId(IXML_Document* doc, DeviceIdStruct *deviceId);

// Metafrazei mia domh EventStruct se soap
IXML_Element *createEvent(IXML_Document* doc, EventList *events);

// Metafrazei enan akeraio se maxenvelopes element
IXML_Element *createMaxEnvelope(IXML_Document* doc, unsigned int maxEnvelope);

// Metafrazei thn hmeromhnia se soap
IXML_Element *createDateTime(IXML_Document* doc, DateTime *currentTime);

// Dhmiourgei to retry count element
IXML_Element *createRetryCount(IXML_Document* doc, unsigned int retryCount);

// Metafrazei mia domh ParameterValueStruct se soap
IXML_Element *createParameterList(IXML_Document* doc, ParameterValueList *parameterListm);

// Dhmiourgei to status element
IXML_Element *createStatus(IXML_Document* doc, unsigned int status);

// Metafrazei mia lista apo sumvoloakolou9es sto ParameterNames element
IXML_Element *createParameterNames(IXML_Document *doc, StringList *parameterNames);

// Dhmiourgei to header se soap me vash to sh
IXML_Node *createHeader(IXML_Document* doc, SoapHeader *sh);
